﻿<Page x:Class="App9.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:Controls="using:App9.Controls"
      xmlns:ViewModels="using:App9.ViewModels"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:local="using:App9"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      mc:Ignorable="d">

    <Page.DataContext>
        <ViewModels:MainPageViewModel />
    </Page.DataContext>

    <Grid Background="SteelBlue">
        <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
            <Rectangle Fill="Black" Opacity=".5" />
            <StackPanel Width="400"
                        Margin="80,60,80,40"
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center">
                <StackPanel DataContext="{Binding User}">
                    <TextBlock Margin="0,0,0,20"
                               Style="{StaticResource HeaderTextBlockStyle}"
                               Text="User profile" />
                    
                    <Controls:ErrorControl Margin="0,5"
                                           DataContext="{Binding FirstName}"
                                           Placement="Left">
                        <Controls:ErrorControl.InnerContent>
                            <TextBox Header="First Name" Text="{Binding Value, 
                                Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                        </Controls:ErrorControl.InnerContent>
                    </Controls:ErrorControl>
                    
                    <Controls:ErrorControl Margin="0,5"
                                           DataContext="{Binding LastName}"
                                           Placement="Left">
                        <Controls:ErrorControl.InnerContent>
                            <TextBox Header="Last Name" Text="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                        </Controls:ErrorControl.InnerContent>
                    </Controls:ErrorControl>
                    <Controls:ErrorControl Margin="0,5"
                                           DataContext="{Binding AcceptTerms}"
                                           Placement="Left">
                        <Controls:ErrorControl.InnerContent>
                            <CheckBox IsChecked="{Binding Value, Mode=TwoWay}">
                                <CheckBox.Content>
                                    <TextBlock>
                                        I agree with the
                                        <Underline>terms and conditions</Underline>
                                    </TextBlock>
                                </CheckBox.Content>
                            </CheckBox>
                        </Controls:ErrorControl.InnerContent>
                    </Controls:ErrorControl>
                </StackPanel>
                <Grid Margin="0,5">
                    <ItemsControl Margin="0,15,0,0"
                                  HorizontalAlignment="Left"
                                  VerticalAlignment="Top"
                                  Foreground="Pink"
                                  ItemsSource="{Binding User.Errors}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding}" />
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                    <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
                        <AppBarButton Command="{Binding RevertCommand}"
                                      Icon="Undo"
                                      Label="Reset" />
                        <AppBarButton Command="{Binding SaveCommand}"
                                      Icon="Save"
                                      Label="Save" />
                    </StackPanel>
                </Grid>
            </StackPanel>
        </Grid>
    </Grid>
</Page>
